package com.katze.boot.system.domain;

import cn.idev.excel.annotation.ExcelIgnoreUnannotated;
import cn.idev.excel.annotation.ExcelProperty;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.katze.boot.common.converter.DateTimeStringConverter;
import com.katze.boot.common.converter.SexConverter;
import com.katze.boot.common.converter.UserStatusConverter;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serial;
import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

@Data
@TableName("sys_user")
@ExcelIgnoreUnannotated
public class User implements Serializable {

    @Serial
    private static final long serialVersionUID = -4852732617765810959L;
    /**
     * 账户状态
     */
    public static final String STATUS_NORMAL = "1";

    public static final String STATUS_LOCK = "0";

    public static final String DEFAULT_AVATAR = "default.jpg";

    /**
     * 性别
     */
    public static final String SEX_MALE = "0";

    public static final String SEX_FEMALE = "1";

    public static final String SEX_UNKNOW = "2";

    // 默认密码
    public static final String DEFAULT_PASSWORD = "1234qwer";

    @TableId(value = "user_id", type = IdType.AUTO)
    private Long userId;

    @ExcelProperty(value = "用户名")
    private String username;

    @ExcelProperty(value = "用户姓名")
    private String firstname;

    @TableField(value = "`password`")
    private String password;

    private Long deptId;

    @ExcelProperty(value = "邮箱")
    private String email;

    @ExcelProperty(value = "手机号")
    private String mobile;

    @ExcelProperty(value = "状态", converter = UserStatusConverter.class)
    @TableField(value = "`status`")
    private String status;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ExcelProperty(value = "创建时间", converter = DateTimeStringConverter.class)
    private Date createTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date modifyTime;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ExcelProperty(value = "最后登录时间", converter = DateTimeStringConverter.class)
    private Date lastLoginTime;

    private String lastLoginIp;

    private String lastLoginLocation;

    @ExcelProperty(value = "性别", converter = SexConverter.class)
    private String sex;

    @ExcelProperty(value = "出生日期")
    private String birthDate;

    @ExcelProperty(value = "联系地址")
    private String address;

    @ExcelProperty(value = "个人描述")
    private String description;

    private String avatar = DEFAULT_AVATAR;

    @ExcelProperty(value = "部门")
    private transient String deptName;

    @ExcelProperty(value = "角色")
    @TableField(exist = false)
    private Set<Role> roles = new HashSet<>();

//    private transient String createTimeFrom;

//    private transient String createTimeTo;

//    private transient String id;
}
